import React, { useEffect } from "react";
import { FormattedMessage } from "react-intl";
import { LibAppView as AppView } from "../../lib";
import { RootApplication } from "../../config/application";

const { useI18n } =  AppView;
const { useApp } = RootApplication;

interface ILoginStatusResponse {
    loginStatus?: any;
}

const Slash = AppView.withService<{}, ILoginStatusResponse>({
    reqEndPoints: [{
        name: "loginStatus",
        endPoint: "login.status"
    }],
    "loadingOptions": {
        "controlled": false,
        "defaultVisible": true,
        "mode": "Skeleton",
        "mountWithLoading": true
    }
})((props) => {
    const app = useApp();
    useEffect(() => {
        if(props.responseData?.afterApiResponse) {
            const statusCode = props.responseData.loginStatus?.statusCode || (props.responseData as any)?.error?.exception?.statusCode;
            if(!/^200$/.test(statusCode)) {
                app.goto("home.login");
            } else {
                app.goto("admin.main");
            }
        }
    }, [props.responseData]);
 console.log(props);
    return (<div>
         
    </div>);
});

export default Slash;
